﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SKDB_Matcher
{
    public partial class CWeightControlItem : UserControl
    {
        private CAbstractAlgorithm m_Algorithm;

        public event EventHandler RaiseCustomEvent;

        protected virtual void OnRaiseCustomEvent(EventArgs e)
        {
            if (RaiseCustomEvent != null)
            {

                // Use the () operator to raise the event.
                RaiseCustomEvent(this,null);
            }

        }



        public CWeightControlItem(CAbstractAlgorithm Algorithm)
        {
            InitializeComponent();
            m_Algorithm = Algorithm;

            labelCaption.Text = m_Algorithm.Caption;
            tbValue.Value = (int)(m_Algorithm.Weight * 100f);
            labelValue.Text = tbValue.Value.ToString() + "%";
        }

        private void tbValue_Scroll(object sender, EventArgs e)
        {
            labelValue.Text = tbValue.Value.ToString() + "%";
            OnRaiseCustomEvent(new EventArgs());
        }

        public void Save()
        {
            m_Algorithm.Weight = tbValue.Value / 100f;
        }

        public void Reset()
        {
            tbValue.Value = (int)(m_Algorithm.Weight * 100f);
            labelValue.Text = tbValue.Value.ToString() + "%";
        }

        public float Weight
        {
            get { return tbValue.Value / 100f; }
            set 
            { 
                tbValue.Value = (int)(value * 100f);
                labelValue.Text = tbValue.Value.ToString() + "%";
            }
        }
    }
}
